<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<div style="height: 20px"></div>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">用户管理</a>
        <a href="#">家长管理</a>
        <a href="#">添加家长</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form  action="" id="parents" onsubmit="return false" style="width:500px;padding-top: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">家长姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" placeholder="家长姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" id="phone" placeholder="手机号" autocomplete="off" class="layui-input">
            <div class="layui-form-mid layui-word-aux"><span style="color: red">登录账号，保存后不可修改</span></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" id="password" placeholder="密码由6-20个字母、数字、下划线组成" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="pass" id="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="add">立即添加</button>
            <button onclick="window.history.go(-1)" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
</body>
<script>
    $("#add").click(function(){
        //手机号
        var mobile=/^[1][3,4,5,7,8][0-9]{9}$/;
        //密码正则  只能输入6-20个字母、数字、下划线
        var patrn = /^(\w){6,20}$/;
        var name = $("#name").val();
        var phone = $("#phone").val();
        var password = $("#password").val();
        var pass = $("#pass").val();
        if(!name){
            layer.msg('家长姓名不能为空',{icon:5,time:2000});
            return
        }
        if(!phone){
            layer.msg('手机号不能为空',{icon:5,time:2000});
            return
        }
        if(!patrn.test(password)){
            layer.msg('密码格式不正确',{icon:5,time:2000});
            return
        }
        if(password != pass){
            layer.msg('两次密码不一致',{icon:5,time:2000});
            return
        }
        $.ajax({
            url:"{:url('/parents/parentsInsert')}",
            data:$("#parents").serialize(),
            type:"post",
            dataType:"json",
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            }
        });
    });
</script>
</html>